import websocket


def on_message(ws, message):
    print(ws)
    print(message)


def on_error(ws, error):
    print(ws)
    print(error)


def on_close(ws):
    print(ws)
    print("### closed ###")


def on_open(ws):
    ws.send("nihao")


def main():
    websocket.enableTrace(True)
    ws = websocket.WebSocketApp("ws://localhost:8080/1",
                                on_open=on_open,
                                on_message=on_message,
                                on_error=on_error,
                                on_close=on_close)
    ws.run_forever()


if __name__ == '__main__':
    main()
